package com.shopping.servlets;

import com.shopping.dao.UserDao;
import com.shopping.dao.impl.UserDaoImpl;
import com.shopping.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName: UserServlet
 * @Description: TODO
 * @Author: JiaShiXi
 * @Date: 2021/3/20 15:26
 * @Version: 1.0
 **/
@WebServlet("/user/user.do")
public class UserServlet extends BaseServlet {

    /**
     * 通过用户ID获取用户信息
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    protected void getUserInfoById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Integer user_id = Integer.parseInt(request.getParameter("user_id"));
        UserDao userDao = new UserDaoImpl();
        User user = userDao.getUserInfoById(user_id);
        request.setAttribute("user",user);
        request.getRequestDispatcher("myself.jsp").forward(request,response);
    }
}
